package basic.不同路径Ⅱ;

/**
 * @author zhengTao
 * @version 1.0
 * @description:  不同路径Ⅱ
 * @date 2022/11/27 17:14
 */
public class Demo63 {
    public static void main(String[] args) {
       int[][] obstacleGrid = {{0,0,0}, {0,1,0},{0,0,0}};
        int i = uniquePathsWithObstacles(obstacleGrid);
    }
    public static int uniquePathsWithObstacles(int[][] obstacleGrid) {
        int[][] dp=new int[obstacleGrid.length][obstacleGrid[0].length];
        for (int i = 0; i < dp.length; i++) {
            for (int j = 0; j < dp[0].length; j++) {
                if(i==0){
                    if(obstacleGrid[i][j]==1){
                        dp[i][j]=0;
                    }else if(j>0){
                        dp[i][j]=dp[i][j-1];
                    }else {
                        dp[i][j]=1;
                    }
                }else if(j==0){
                    if(obstacleGrid[i][j]==1){
                        dp[i][j]=0;
                    }else {
                        dp[i][j]=dp[i-1][j];
                    }
                }else {
                    if(obstacleGrid[i][j]==1){
                        dp[i][j]=0;
                    }else {
                        dp[i][j]=dp[i][j-1]+dp[i-1][j];
                    }

                }
            }
        }
      /*  for (int i = 0; i < dp.length; i++) {
            for (int j = 0; j < dp[0].length; j++) {
                System.out.println("行"+i+"列"+j+":"+dp[i][j]);
            }
        }*/
        return dp[dp.length-1][dp[0].length-1];
    }
}
